var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
function unload(url,data){
    if (isAndroid) { //安卓
        if (window.addEventListener) {
            document.addEventListener("visibilitychange", function () { //部分手机可以获取到
                if (document.hidden) {
                    addBrowseLog(url,data);
                }
            })
    
        } else if (window.attachEvent) {
            // 主要是为了兼容老的IE
            window.attachEvent('onpagehide', function () {
                addBrowseLog(url,data);
            })
    
        } else {
            window.onbeforeunload = function () {
                addBrowseLog(url,data);
            }
        }
    
    } else { //苹果
        window.addEventListener("pagehide", function (e) {
            addBrowseLog(url,data);
        }, false);
    
    }
}

function addBrowseLog(url,data) {
    let blob = new Blob([JSON.stringify(data)], {
        type: 'application/json; charset=UTF-8',
    });
    navigator.sendBeacon(url, blob);
}


// export default{
//     install (Vue, options){
//         Vue.prototype.$unload = unload
//     }
// }